package com.woniu.core.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.core.entity.CoreBlacklist;
import com.woniu.core.entity.CoreTenderRecord;
import com.woniu.core.entity.CoreUser;
import com.woniu.core.mapper.CoreBlacklistMapper;
import com.woniu.core.mapper.CoreUserMapper;
import com.woniu.core.service.CoreBlacklistService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoreBlacklistServiceImpl implements CoreBlacklistService {

    @Autowired
    private CoreBlacklistMapper coreBlacklistMapper;
    @Autowired
    private CoreUserMapper coreUserMapper;

    @Override
    public HttpResult<?> selectCoreBlacklist(RequestResult<CoreBlacklist> param) {
        String coreId = coreUserMapper.selectUserCoreIdByUserAccount(param.getData().getCoreId());
        param.getData().setCoreId(coreId);
        try {
            PageHelper.startPage(param.getPageNum(), param.getPageSize());
            List<CoreBlacklist> records = coreBlacklistMapper.selectCoreBlacklist(param.getData());
            PageInfo<CoreBlacklist> pageInfo = new PageInfo<>(records);
            return new HttpResult<>().ok(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> addCoreBlacklist(String financingEnterpriseId, String account) {
        try {
            CoreUser coreUser = coreUserMapper.selectUserByUserAccount(account);
            CoreBlacklist coreBlacklist = new CoreBlacklist();
            coreBlacklist.setCoreId(coreUser.getUserCoreId());
            coreBlacklist.setCreateUser(coreUser.getUserName());
            coreBlacklist.setEnterpriseId(financingEnterpriseId);
            coreBlacklistMapper.addCoreBlacklist(coreBlacklist);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> deleteCoreBlacklist(Integer id) {
        coreBlacklistMapper.deleteCoreBlacklist(id);
        return new HttpResult<>().ok();
    }
}
